#!/usr/bin/env python
# -*- coding:utf-8 -*-
# File:chat_demo.py
# Author:yuanronghao
# Time:2023/3/23 12:44
# Software:PyCharm

import openai
from configparser import ConfigParser

CONFIG = ConfigParser()
CONFIG.read('system.conf', encoding='utf-8')
openai.organization = CONFIG['ORG_ID']['ORG_ID']
openai.api_key = CONFIG['API_KEYS']['OPENAI_API_KEY']

# 输出当前可用模型
print(openai.Model.list(), "\n")

# 创建一次chat请求
content = "请给我一篇关于美国硅谷的简介，200字"
completion = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "user", "content": content}
    ],
    temperature=0.7,
    top_p=1,
    n=1,
    stop=None,
    max_tokens=1000,
)  # 详细参数参见 https://platform.openai.com/docs/api-reference/chat/create

print("response: ", completion)
print(completion.choices[0].message['content'])
